Skip to content

fix(openai): align Decisions spans with Python SDK - #2723

Merged
Luca Forstner (lforst) merged 1 commit into
mainfrom
ankur/decision-spans-python-ids
Nov 3, 2026
Merged

Luca Forstner (lforst) merged 1 commit into
mainfrom
ankur/decision-spans-python-ids

Conversation

@ankrgyl

@ankrgyl Ankur Goyal (ankrgyl) commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The JS and Python SDKs log OpenAI Decisions calls differently. We agreed to standardize on Python's behavior, which the Braintrust gateway also follows (braintrustdata/braintrust#24288). This PR switches JS to it.

Before (JS) After (matches Python)
Span type question decision
ID for an unnamed or repeated question String(index) question_{index}, with _ appended until it's unique
Pairing answers with questions by position by name first, then remaining questions in order
A boolean choice whose text matches a string choice every key is JSON-quoted the boolean's key gets a boolean: prefix; string keys stay as they are
Score criteria "label: description" strings {label, description} objects

This brings JS in line with the decision span spec (braintrustdata/braintrust-spec#82), which says new instrumentation must emit the decision span type.

Testing

  • pnpm exec vitest run src/instrumentation/plugins/openai-decisions.test.ts passes (21 tests). One test is new: repeated and unnamed questions, with answers in a different order. Against the old instrumentation, 5 of the tests fail.
  • Updated the openai-instrumentation e2e assertions and regenerated its snapshots with test:e2e:update; no new recordings were needed. The only snapshot changes are the span type and the score-criteria shape. I then ran the normal e2e tests twice; both passed (729 tests).
  • pnpm run check:typings and eslint pass on the changed files.

🤖 Generated with Claude Code

Co-authored by StarfolkAI (@starfolkai)[bot]

Log OpenAI Decisions calls the way the Python SDK and the Braintrust
gateway do, so the same call produces the same decision span:

- use the decision span type instead of the legacy question type
- give unnamed or repeated questions question_{index} IDs, and pair
  answers with questions by name before position
- prefix boolean choice keys with boolean: only when they collide with
  a string choice, instead of quoting every key
- log score criteria as {label, description} objects

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-03T00:31:26.092511Z ca9dafb PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ca9dafb786

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "Codex (@codex) review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "Codex (@codex) address that feedback".

const answers = value.answers.map((answer, index) => {
const { name, ...rest } = answer;
const id = name ?? args[0].questions[index]?.name ?? String(index);
const pairs = decisionAnswers(value.answers, args[0].questions);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Snapshot questions before awaiting the decision

If a caller reuses or clears params.questions after decisions.create() returns but before the response resolves, this rereads the live request and can drop or misassociate every output answer, even though the input IDs were already captured from the original questions. Previously, named answers did not depend on the later request state; retain the computed IDs and corresponding question data at span creation and use that snapshot during result extraction.

Useful? React with 👍 / 👎.

@lforst
Luca Forstner (lforst) merged commit f42d9dc into main Nov 3, 2026
61 checks passed
@lforst
Luca Forstner (lforst) deleted the ankur/decision-spans-python-ids branch November 3, 2026 13:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants